//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:20-3-16
// @Time:下午2:04
//

#include "SingletonObject.h"

bool SingletonObject::saveUserdata(std::string username, std::string data)
{
 std::pair<std::map<std::string,std::string>::iterator,bool> ret;
 ret = userMap.insert(std::pair<std::string,std::string>(username,data));
 // 插入结果
 if(ret.second)
 {
     //成功
     return true;
 } else
 {
     // 失败
     return false;
 }
}

std::string SingletonObject::getUserData(std::string username) const
{
    // 判断是否 有数据
    if (userMap.count(username)>0)
    {
        // 存在 返回
        return userMap.at(username);
    } else
    {
        // 不存在 返回 空
        return "";
    }
}

bool SingletonObject::deleteUserData(std::string username)
{
    if(userMap.count(username)>0)
    {
        //存在数据 删除
        userMap.erase(username);
        return true;
    } else
    {
        return false;
    }
}

SingletonObject::~SingletonObject()
{
    std::cout<<" delete SingletonObject name = "<<singletonname<<std::endl;
}

SingletonObject::SingletonObject(const SingletonObject &s)
{
    std::cout<<" construct SingletonObject by name = "<<s.singletonname<<std::endl;
    this->singletonname=s.singletonname;
    this->userMap=s.userMap;
}

SingletonObject::SingletonObject()
{
    std::cout<<" init empty SingletonObject"<<std::endl;
}

void SingletonObject::setSingletonname(const std::string &singletonname)
{
    SingletonObject::singletonname = singletonname;
}

const std::string &SingletonObject::getSingletonname() const
{
    return singletonname;
}
